home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibList.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  3.5 KB  |  153 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display    *dpy;
  5. extern GC     mib_gc;
  6. static Widget    real_list;
  7.  
  8. /* Code for Lists */
  9. /*****************************************************************************/
  10.  
  11. mib_Widget *mib_create_List(mib_Widget *parent, char *name, char *label,
  12.         int posx, int posy, int width, int height, int mib_fill)
  13. {
  14.   mib_Widget    *temp;
  15.   mib_List    *myres;
  16.   Widget     wtemp;
  17.   unsigned char *label_text;
  18.   char         ttext[30];
  19.   Arg         args[20];
  20.   String     myname;
  21.   int         n;
  22.  
  23.   /* create the new widget and add it to the tree */
  24.  
  25.   temp = mib_new_mib_Widget();
  26.   if (mib_fill == WDEFAULT)
  27.     mib_add_backward(temp, parent);
  28.   else
  29.     mib_add_mib_Widget(temp, parent);
  30.  
  31.   myres = (mib_List *)malloc(sizeof(mib_List));
  32.  
  33.   /* initialize public resources */
  34.  
  35.   if (mib_fill == WDEFAULT)
  36.   {
  37.     temp->name = (char *)malloc(strlen(name)+1);
  38.     strcpy(temp->name,name);
  39.   }
  40.   temp->mib_class = (char *)malloc(5);
  41.   sprintf(temp->mib_class,"List");
  42.   temp->mib_class_num = MIB_LIST;
  43.   temp->width = width;
  44.   temp->height = height;
  45.   temp->topOffset = posy;
  46.   temp->leftOffset = posx;
  47.   temp->bottomOffset = 0;
  48.   temp->rightOffset = 0;
  49.   temp->topAttachment = 1;
  50.   temp->leftAttachment = 1;
  51.   temp->bottomAttachment = 0;
  52.   temp->rightAttachment = 0;
  53.  
  54.   temp->mib_allowresize = 1;
  55.  
  56.   /* initialize private resources */
  57.  
  58.   temp->myres = (void *)myres;
  59.  
  60.   /* create Xt widget */
  61.  
  62.   n = 0;
  63.  
  64.   if (mib_fill == WDEFAULT)
  65.   {
  66.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  67.     XtSetArg (args[n], XmNleftOffset, posx); n++;
  68.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  69.     XtSetArg (args[n], XmNtopOffset, posy); n++;
  70.   }
  71.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  72.   XtSetArg (args[n], XmNshadowType, XmSHADOW_ETCHED_IN); n++;
  73.  
  74.   temp->me = XtCreateManagedWidget(name, xmFrameWidgetClass,
  75.                 temp->parent->me, args, n);
  76.  
  77.   n = 0;
  78.  
  79.   if (mib_fill == WDEFAULT)
  80.   {
  81.     XtSetArg (args[n], XmNwidth, width); n++;
  82.     XtSetArg (args[n], XmNheight, height); n++;
  83.   }
  84.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  85.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  86.   XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  87.  
  88.   if (mib_fill == WEMPTY)
  89.   {
  90.     XtSetArg (args[n], XmNlistSizePolicy, XmCONSTANT); n++;
  91.   }
  92.  
  93.   wtemp = XmCreateScrolledList(temp->me, name, args, n);
  94.   myres->real_list = wtemp;
  95.   real_list = wtemp;
  96.  
  97.   XtManageChild(wtemp);
  98.  
  99.   if (mib_fill != WEMPTY)
  100.     real_list = NULL;
  101.  
  102.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  103.   {
  104.     label_text = XmStringCreateLtoR("Simple", XmSTRING_DEFAULT_CHARSET);
  105.     XmListAddItem(wtemp, label_text, 0);
  106.     XmStringFree(label_text);
  107.     label_text = XmStringCreateLtoR("List", XmSTRING_DEFAULT_CHARSET);
  108.     XmListAddItem(wtemp, label_text, 0);
  109.     XmStringFree(label_text);
  110.     for (n=0;n<200;n++)
  111.     {
  112.       sprintf(ttext,"Item %d   ",n);
  113.       label_text = XmStringCreateLtoR(ttext, XmSTRING_DEFAULT_CHARSET);
  114.       XmListAddItem(wtemp, label_text, 0);
  115.       XmStringFree(label_text);
  116.     }
  117.  
  118.     mib_apply_eventhandlers(temp->me, temp);
  119.     mib_apply_eventhandlers(wtemp, temp);
  120.   }
  121.  
  122.   return temp;
  123. }
  124.  
  125. void mib_delete_List(mib_Widget *this)
  126. {
  127.   mib_List *temp = (mib_List *)this->myres;
  128.  
  129.   free(temp);
  130. }
  131.  
  132. void mib_save_List(mib_Widget *this, FILE *fout)
  133. {
  134. }
  135.  
  136. int mib_load_List(mib_Widget *this, mib_Buffer *fin)
  137. {
  138.   char        res[MI_MAXSTRLEN];
  139.   char        val[MI_MAXSTRLEN];
  140.  
  141.  
  142.   if (real_list)
  143.    this->me = real_list;
  144.  
  145.   if (!mib_read_line(fin, res, val))
  146.     return 0;
  147.  
  148.   if (strcmp(res,"EndWidget"))
  149.     return 0;
  150.  
  151.   return 1;
  152. }
  153.